Intrinsic String Manipulation Types
例
code:ts
type EnthusiasticGreeting<T extends string> = ${Uppercase<T>}
type HELLO = EnthusiasticGreeting<"hello">;
// same as
// type HELLO = "HELLO";
code:ts
type T10 = Uppercase<'hello'>; // "HELLO"
type T11 = Lowercase<'HELLO'>; // "hello"
type T12 = Capitalize<'hello'>; // "Hello"
type T13 = Uncapitalize<'Hello'>; // "hello"
type T20 = Uppercase<'foo' | 'bar'>; // "FOO" | "BAR"
type T21 = Lowercase<'FOO' | 'BAR'>; // "foo" | "bar"
type T22 = Capitalize<'foo' | 'bar'>; // "Foo" | "Bar"
type T23 = Uncapitalize<'Foo' | 'Bar'>; // "foo" | "bar"
type T30<S extends string> = Uppercase<aB${S}>;
type T31 = T30<'xYz'>; // "ABXYZ"
type T32<S extends string> = Lowercase<aB${S}>;
type T33 = T32<'xYz'>; // "abxyz"
type T34 = ${Uppercase<'abc'>}${Lowercase<'XYZ'>}; // "ABCxyz"
type T40 = Uppercase<string>; // string
type T41 = Uppercase<any>; // any
type T42 = Uppercase<never>; // never
type T43 = Uppercase<42>; // Error, type 'number' does not satisfy the constraint 'string'
定義を直接見に行っても見れない、処理系依存の型になっている
code:ts
type Uppercase<S extends string> = intrinsic;